<template>
  <el-form :model="modelValue" ref="formRef" label-width="80px">
    <el-form-item label="服务类型" prop="serviceId" :rules="[{ required: true, message: '请选择服务' }]">
      <el-select v-model="modelValue.serviceId" placeholder="请选择">
        <el-option v-for="s in services" :key="s.id" :label="s.name" :value="s.id"/>
      </el-select>
    </el-form-item>
    <el-form-item label="预约时间" prop="date" :rules="[{ required: true, message: '请选择时间' }]">
      <el-date-picker v-model="modelValue.date" type="datetime" placeholder="选择时间"/>
    </el-form-item>
    <el-button @click="$emit('prev')">上一步</el-button>
    <el-button type="primary" @click="handleNext">下一步</el-button>
  </el-form>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { getServiceList } from '@/api/service'
const props = defineProps(['modelValue'])
const emit = defineEmits(['update:modelValue', 'next', 'prev'])
const formRef = ref(null)
const services = ref([])

onMounted(async () => {
  const res = await getServiceList()
  services.value = res.data
})

function handleNext() {
  formRef.value.validate((valid) => {
    if (valid) emit('next')
  })
}
</script> 